<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    

    <script>
        function dispatch(action) {
            if (typeof action !== "object") {
                throw new Error("action必须是一个对象")
            } else {
                if (action.type) {
                    console.log('流程走通')
                } else {
                    throw new Error("action中必须有type属性")
                }
            }
        }

        // 保留了原代码
        let oldDispatch = dispatch

        // 修改源代码
        dispatch = (action) => {
            if (typeof action === "function") {
                console.log('我现在可以传递函数了~')
            } else {
                oldDispatch(action)
            }
        }

        // console.log(dispatch)
        dispatch((next = oldDispatch) => {
            console.log(next)
            next({ type: "DEL" })
        })

        // dispatch({ type: "ADD" })
        // dispatch(() => {

        // })
    </script>
</body>
</html>